﻿using System;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;

namespace ui_test.ViewModels;

public partial class UserControl2ViewModel : ViewModelBase
{
    public ObservableCollection<ISeries<int>> Series { get; }

    public UserControl2ViewModel()
    {
        Console.WriteLine("user control2 init ...");
        Series =
        [
            new ColumnSeries<int>()
            {
                Name = "Key Count",
                YToolTipLabelFormatter = point => $"{point.Model}times",
                DataLabelsPaint = new SolidColorPaint()
                {
                    Color = SKColors.Crimson,
                    IsFill = true,
                },

                Values = new[]
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
                    11, 12, 13, 14, 15, 16, 17,
                    18, 19, 20, 21, 22, 23, 34, 35, 36,
                }
            }
        ];
    }

    [RelayCommand]
    private void UpdateData()
    {
        if (Series[0] is ColumnSeries<int> series)
        {
            var ints = new ObservableCollection<int>();
            var random = new Random();
            for (int i = 0; i < 26; i++)
            {
                var next = random.Next(100, 2000);
                ints.Add(next);
            }

            series.Values = ints;
        }
    }


    public Axis[] XAxes { get; set; } =
    {
        new()
        {
            Labels = new[]
            {
                "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
                "K", "L", "M", "O", "P",
                "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
            },
            LabelsRotation = 0,
            SeparatorsPaint = new SolidColorPaint(new SKColor(200, 200, 200)),
            SeparatorsAtCenter = false,
            TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),
            TicksAtCenter = true,
            // By default the axis tries to optimize the number of 
            // labels to fit the available space, 
            // when you need to force the axis to show all the labels then you must: 
            ForceStepToMin = true,
            MinStep = 1
        }
    };
}